import requests


class UserApi(object):


    @classmethod
    def add_user(cls, headers, body):
        """
        根据请求体信息，新增用户接口
        :param headers: 请求头-包含令牌
        :param body: 请求体
        :return: 响应对象
        """
        url = "http://ihrm-test.itheima.net/api/sys/user"
        response = requests.post(url=url, headers=headers, json=body)
        return response

    @classmethod
    def query_user(cls, headers, id):
        """
        根据id，查询用户
        :param headers: 请求头
        :param id: 用户的id
        :return: 响应对象
        """
        url = "http://ihrm-test.itheima.net/api/sys/user/" + id
        response = requests.get(url=url, headers=headers)
        return response

    @classmethod
    def modify_user(cls, headers, id, body):
        """
        根据id和请求体，修改用户信息
        :param headers: 请求头
        :param id: 用户id
        :param body: 请求体
        :return: 响应对象
        """
        url = "http://ihrm-test.itheima.net/api/sys/user/" + id
        response = requests.put(url=url, headers=headers, json=body)
        return response

    @classmethod
    def delete_user(cls, headers, id):
        """
        根据id，删除用户
        :param headers:请求头
        :param id: 用户id
        :return: 响应对象
        """
        url = "http://ihrm-test.itheima.net/api/sys/user/" + id
        response = requests.delete(url=url, headers=headers)
        return response


if __name__ == '__main__':
    headers = {"Content-Type": "application/json",
               "Authorization": "Bearer 67c8f3db-8b57-421b-b2e6-4c4dfaf721be"}
    login_body = {
        "username": "YG",
        "mobile": "18210222013",
        "workNumber": "123"
    }
    resp = UserApi.add_user(headers, login_body)
    print(resp.json())

    id = "1518788936334426112"
    resp = UserApi.query_user(headers=headers, id=id)
    print("查询user结果：", resp.json())

    modify_body = {
        "username": "YG002",
        "password": "123456",
        "departmentId": "10086"
    }

    resp = UserApi.modify_user(headers=headers, id=id, body=modify_body)
    print("修改user", resp.json())

    resp = UserApi.delete_user(headers, id)
    print("删除user:", resp.json())
